package com.heima.article.listen;

import com.heima.article.service.ApArticleService;
import com.heima.common.constants.message.PublishArticleConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @package com.heima.article.listen
 * @Date 2022/3/5
 * @project heima-leadnews
 */
@Slf4j
@Component
public class PublishArticleListener {
    @Autowired
    ApArticleService apArticleService;
    @RabbitListener(queuesToDeclare = {@Queue(
            value = PublishArticleConstants.PUBLISH_ARTICLE_QUEUE
    )})
    public void publishArtivle(String newsId){
        log.info("接收到发布文章的通知 文章{}",newsId);
        try {
            apArticleService.publishArticle(Integer.valueOf(newsId));
        } catch (NumberFormatException e) {
            e.printStackTrace();
            log.error("文章发布失败失败原因{}",e.getMessage());
        }
    }
}
